package edu.networkpro;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class IPDemo {
    public static void main(String[] args) throws UnknownHostException {
        //根据域名   www.tmall.com
        InetAddress inetAddress = InetAddress.getByName("www.tmall.com");
        //解析对应地址
        System.out.println(inetAddress);
        //获取主机地址ip
        System.out.println(inetAddress.getHostAddress());
        //获取主机名称
        System.out.println(inetAddress.getHostName());
        //获取主机信息
        InetAddress localHost = InetAddress.getLocalHost();
        String hostAddress = localHost.getHostAddress();
        System.out.println("hostAddress = " + hostAddress);
        System.out.println(localHost.getHostName());

    }
}
